<!-- profile -->
<template>
  <div>
    <!-- 已登录 -->
    <div class="my_title" v-if="$store.state.Usertoken">
      <img
        src="http://liufusong.top:8080/img/avatar.png"
        alt=""
        style="width: 100%"
      />
      <div class="user" style="top: 150px">
        <div class="my_picture">
          <img src="http://liufusong.top:8080/img/profile/avatar.png" alt="" />
        </div>
        <div class="text">
          <p>游客</p>
          <div class="textBtn" style="border-radius: 50px" @click="quit">退出</div>
          <span>
            编辑个人资料
            <van-icon name="arrow" />
          </span>
        </div>
      </div>
    </div>
    <!-- 未登录 -->
    <div class="my_title" v-else>
      <img
        src="http://liufusong.top:8080/img/profile/bg.png"
        alt=""
        style="width: 100%"
      />
      <div class="user">
        <div class="my_picture">
          <img src="http://liufusong.top:8080/img/profile/avatar.png" alt="" />
        </div>
        <div class="text">
          <p>游客</p>
          <div class="textBtn" @click="$router.replace('/login')">去登录</div>
        </div>
      </div>
    </div>

    <van-grid :column-num="3">
      <van-grid-item text="我的收藏" @click="clickFn1">
        <template #icon>
          <van-icon name="star-o" />
        </template>
      </van-grid-item>
      <van-grid-item text="我的出租" @click="clickFn2">
        <template #icon>
          <van-icon name="wap-home-o" />
        </template>
      </van-grid-item>
      <van-grid-item text="看房记录">
        <template #icon>
          <van-icon name="clock-o" />
        </template>
      </van-grid-item>
      <van-grid-item text="成为房主">
        <template #icon>
          <van-icon class="iconfont icon-24gl-debitCard" />
        </template>
      </van-grid-item>
      <van-grid-item text="个人资料">
        <template #icon>
          <van-icon class="iconfont icon-31wode" />
        </template>
      </van-grid-item>
      <van-grid-item text="联系我们">
        <template #icon>
          <van-icon class="iconfont icon-lianxiwomen" />
        </template>
      </van-grid-item>
    </van-grid>
    <div class="footer">
      <img src="http://liufusong.top:8080/img/profile/join.png" alt="">
    </div>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'
import { Dialog } from 'vant'
import store from '@/store'
export default {
  data () {
    return {
      store
    }
  },
  created () {
    // console.log(this.$store.state.Usertoken)
  },
  methods: {

    ...mapMutations,
    quit () {
      Dialog.confirm({
        title: '提示',
        message: '这就走了?不爱我了吗?'
      }).then(() => {
        // 清空vuex和本地
        // this.setToken('')
        this.$store.commit('setToken', '')
        // this.$router.replace('/layout/profile')
        // console.log(this.$store.state.Usertoken)
      }).catch(() => {
        // on cancel
      })
    },
    clickFn1 () {
      if (this.$store.state.Usertoken) {
        this.$router.push('/collect')
      } else {
        this.$router.replace('/login')
      }
    },
    clickFn2 () {
      if (this.$store.state.Usertoken) {
        this.$router.push('/publish')
      } else {
        this.$router.replace('/login')
      }
    }
  }
}
</script>
<style lang='less' scoped>
.my_title {
  position: relative;
  min-height: 300px;
  margin-bottom: 30px;
  .user {
    position: absolute;
    background: #fff;
    width: 85%;
    height: 55%;
    top: 85px;
    left: 30px;
    box-shadow: 0 0 10px 3px #ddd;
    margin: 50px auto 0;
    padding: 0 20px;
    text-align: center;
    font-size: 13px;
    box-sizing: border-box;
    .my_picture {
      position: relative;
      width: 70px;
      height: 70px;
      top: -40px;
      left: 50%;
      transform: translateX(-50%);
      border-radius: 50%;
      border: 5px solid #f5f5f5;
      img {
        width: 100%;
      }
    }
    .text {
      margin-top: -30px;
      margin-bottom: 20px;
      p {
        margin-bottom: 20px;
      }
      .textBtn {
        position: relative;
        // top: 50px;
        left: 50%;
        transform: translateX(-50%);
        width: 70px;
        height: 30px;
        background-color: #58b67e;
        color: #fff;
        line-height: 30px;
        border-radius: 4px;
        margin-bottom: 20px;
      }
      span {
        color: #999;
      }
    }
  }
}
.footer {
  width: 350px;
  height: 100px;
  margin-top: 20px;
  margin-left: 15px;
  img {
    width: 100%;
  }
}
</style>
